package com.xuelang.pipeline.client.pipeline.enums;

import lombok.Getter;

/**
 * @author liuyuan.ly
 * @since 2024/6/27 14:35
 */
@Getter
public enum PipelineInstanceEnum {
    notStart(0, "notStart"),
    running(1, "running"),
    waiting(2, "waiting"),
    success(3, "success"),
    failed(4, "fail"),
    terminated(5, "terminated"),
    ;

    final Integer key;
    final String value;

    PipelineInstanceEnum(Integer key, String value) {
        this.key = key;
        this.value = value;
    }

    public static PipelineInstanceEnum fromValue(String value) {
        for (PipelineInstanceEnum pipelineInstanceEnum : values()) {
            if (pipelineInstanceEnum.value.equals(value)) {
                return pipelineInstanceEnum;
            }
        }
        throw new IllegalArgumentException("Invalid value: " + value);
    }

    public static PipelineInstanceEnum fromKey(Integer key) {
        for (PipelineInstanceEnum pipelineInstanceEnum : values()) {
            if (pipelineInstanceEnum.key.equals(key)) {
                return pipelineInstanceEnum;
            }
        }
        throw new IllegalArgumentException("Invalid value: " + key);
    }
}
